home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 87 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: eua.ericsson.se!usenet
  2. From: euahjn@eua.ericsson.se (Henrik Johansson)
  3. Newsgroups: comp.unix.programmer,comp.lang.c++
  4. Subject: Re: ?? pointer to function in C++
  5. Date: 2 Jan 1996 08:39:33 GMT
  6. Organization: Ericsson Telecom Systems Labs, Stockholm, Sweden
  7. Distribution: world
  8. Message-ID: <4car05$hoi@euas20.eua.ericsson.se>
  9. References: <4c2pm4$69d@enterprise.sct.gu.edu.au>
  10. Reply-To: euahjn@eua.ericsson.se
  11. NNTP-Posting-Host: euas31i2c37.eua.ericsson.se
  12.  
  13. In article <4c2pm4$69d@enterprise.sct.gu.edu.au>, Peter Kese <peter.kese@cit.gu.edu.au> writes:
  14. > Hi!
  15. > I am trying to use pointers to C++ class functions (methods), which don't seem
  16. > to work. My program (class) should look something like this:
  17. > class myclass {
  18. >   void (*selected)();   // a pointer to a function / method
  19. > public:
  20. >   void method1(){ ... };
  21. >   void method2(){ ... };
  22. >   myclass(){                       // constructor
  23. >     selected_method = method1;     // set selected_method   (this fails)
  24. > //or selected_method = method2;
  25. >   };
  26. >   callselected(){ selected_method() } // call the selected_method;
  27. > };
  28. > It seems that C++ does not let me obtain a method address:
  29. >   void *someptr = method1   // this doesn't work
  30. > Can someone help me?  (I am working on Unix (SGI, Sun) with CC or gcc)
  31. > -- 
  32. > Peter Kese
  33.  
  34. See section 18 in the FAQ: Pointers to member functions
  35.  
  36.  
  37.  
  38.